<?php

header("Content-type: text/html; charset=utf-8");

$admin = false;
require_once('auth_req.inc.php');

$use_opt = 0;

if($_GET['type'] == 'opt')
{
    $use_opt = 1;
}
elseif ($_GET['type'] == 'str')
{
    $use_opt = 2;
}

$rs = $dbh->query('select c_id,location from network_map order by c_id');

$alldb = $rs->fetchAll(PDO::FETCH_ASSOC);

$str = '';

foreach( $alldb as $key => $val)
{
    switch($use_opt)
    {
        default:
            $response[$key]['id'] = intval($val['c_id']);
            $response[$key]['location'] = $val['location'];
        break;

        case 1:
            echo '<option value="' . $val['c_id'] . '">' . $val['c_id'] . (empty($val['location'])? '' : '-'. $val['location']) . "</option>\n";
        break;

        case 2:

            if (!empty($str))
                $str .= ';';

            $str .= $val['c_id'] . ":" . $val['c_id'];
        break;

    }
}

switch($use_opt)
{
    case 0:
        echo json_encode($response);
    break;

    case 2:            
        echo $str;
    break;
}

?>
